<?php
/**
 * Created by PhpStorm.
 * User: dell
 * Date: 2017/7/27
 * Time: 14:46
 */

namespace Home\Service;


use Common\Common\Service;
use Home\Exception\HomeException;
use Home\Model\UserWeixin\UserWeixinModel;
use Home\Request\User_weixin\GetWeixinIdRequest;
use Home\Response\GetWeixinIdResponse;

class GetWeixinIdService implements Service
{
    public function run(GetWeixinIdRequest $request = null)
    {
        $user_id = $request->getUserId();
        $component = new UserWeixinModel();
        $response = new GetWeixinIdResponse();
        try {
            $result = $component->getWeixinId($user_id);
            $weixin_id = $result['weixin_id'];
            if (is_null($weixin_id) == false) {
                $response->setWeixinId($weixin_id);
            } else {
                $response->setItIsNull();
            }
        } catch (HomeException $e) {
            throw new HomeException($e->getMessage(), $e->getCode());
        }
        return $response;
    }
}